import time
from . import ConnPG
import psycopg2


class SelectDuty:

    async def select_all_duty(self):#查询所有职务名称


        sql = 'select * from duty'


        result = await ConnPG().fetchall(sql)



        return {
            'status': 1,
            'errorCode': None,
            'errorMsg': None,
            'resultBody': result,
        }

    

    async def select_user_by_duty(self, duty_id):#查询职务下有哪些人员

        #参数检查

        if duty_id == None or not duty_id.isdecimal():

            return {
                'status': -1,
                'errorCode': 104100,
                'errorMsg': '参数错误，接口有一个必传参数且为整数',
                'resultBody': None
            }

        duty_id = int(duty_id)

        sql = 'select * from view_user_duty where duty_id=%s'

        result = await ConnPG().fetchall(sql, (duty_id,))
        return {
            'status': 1,
            'errorCode': None,
            'errorMsg': None,
            'resultBody': result,
        }

    
    async def select_duty_by_user_id(self, user_id):#用户ID查询职务

        #参数检查

        if user_id == None or not user_id.isdecimal():

            return {
                'status': -1,
                'errorCode': 104100,
                'errorMsg': '参数错误，接口有一个必传参数且为整数',
                'resultBody': None
            }

        sql = 'select * from view_user_duty where id=%s'

        result = await ConnPG().fetchall(sql, (user_id,))
        return {
            'status': 1,
            'errorCode': None,
            'errorMsg': None,
            'resultBody': result,
        }